home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / Roger / Roger.jar / Roger$AnimationCanvas.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-08-31  |  4.6 KB  |  128 lines

  1. import javax.microedition.lcdui.Canvas;
  2. import javax.microedition.lcdui.Graphics;
  3. import javax.microedition.lcdui.StringItem;
  4.  
  5. class Roger$AnimationCanvas extends Canvas implements Runnable {
  6.    int currentImg;
  7.    Roger$AnimationCanvas$BallsEngine ballsEngine;
  8.    boolean goOn;
  9.    // $FF: renamed from: t java.lang.Thread
  10.    Thread field_0;
  11.    int minX;
  12.    int maxX;
  13.    // $FF: renamed from: x int
  14.    int field_1;
  15.    // $FF: renamed from: y int
  16.    int field_2;
  17.    long start;
  18.    boolean end;
  19.    // $FF: synthetic field
  20.    private final Roger this$0;
  21.  
  22.    Roger$AnimationCanvas(Roger this$0) {
  23.       this.this$0 = this$0;
  24.       this.currentImg = 0;
  25.       this.goOn = true;
  26.       this.field_0 = null;
  27.       this.ballsEngine = new Roger$AnimationCanvas$BallsEngine(this);
  28.       Roger.access$1402(this$0, ((Canvas)this).getWidth());
  29.       Roger.access$1502(this$0, ((Canvas)this).getHeight());
  30.       this.minX = 0;
  31.       this.maxX = Roger.access$1400(this$0) - 20;
  32.    }
  33.  
  34.    void init() {
  35.       this.field_1 = Roger.access$1400(this.this$0) / 2 - 10;
  36.       this.field_2 = Roger.access$1500(this.this$0) - 1;
  37.       System.out.println("within init() x=" + this.field_1 + " y=" + this.field_2 + " width=" + Roger.access$1400(this.this$0) + " height=" + Roger.access$1500(this.this$0));
  38.    }
  39.  
  40.    public void run() {
  41.       System.out.println("start of the run() method");
  42.  
  43.       while(this.goOn) {
  44.          ((Canvas)this).repaint();
  45.          ((Canvas)this).serviceRepaints();
  46.          this.ballsEngine.tick();
  47.  
  48.          try {
  49.             Thread.sleep(150L);
  50.          } catch (Exception var2) {
  51.             ((Throwable)var2).printStackTrace();
  52.          }
  53.       }
  54.  
  55.       System.out.println("end of the run loop within the run() method");
  56.       Roger.access$600(this.this$0).append(new StringItem("score", " " + (System.currentTimeMillis() - this.start) / 1000L));
  57.       Roger.access$1200(this.this$0).setCurrent(Roger.access$600(this.this$0));
  58.       System.out.println("end of run()");
  59.    }
  60.  
  61.    void startAnimation() {
  62.       this.ballsEngine.init(Roger.access$1400(this.this$0), Roger.access$1500(this.this$0));
  63.       this.start = System.currentTimeMillis();
  64.       this.end = false;
  65.       this.goOn = true;
  66.       if (this.field_0 == null) {
  67.          this.field_0 = new Thread(this);
  68.          this.field_0.start();
  69.       }
  70.  
  71.    }
  72.  
  73.    void stopAnimation() {
  74.       this.goOn = false;
  75.       this.field_0 = null;
  76.    }
  77.  
  78.    protected void keyPressed(int keyCode) {
  79.       System.out.println("within the keyPressed");
  80.       switch (((Canvas)this).getGameAction(keyCode)) {
  81.          case 2:
  82.             this.left();
  83.             break;
  84.          case 5:
  85.             this.right();
  86.       }
  87.  
  88.    }
  89.  
  90.    void left() {
  91.       if (this.field_1 > 4) {
  92.          this.field_1 -= 5;
  93.       }
  94.  
  95.    }
  96.  
  97.    void right() {
  98.       if (this.field_1 < Roger.access$1400(this.this$0) - 24) {
  99.          this.field_1 += 5;
  100.       }
  101.  
  102.    }
  103.  
  104.    public void paint(Graphics g) {
  105.       System.out.println("within paint  x=" + this.field_1 + " y=" + this.field_2);
  106.       g.setGrayScale(255);
  107.       g.fillRect(0, 0, Roger.access$1400(this.this$0), Roger.access$1500(this.this$0));
  108.       g.drawImage(Roger.access$000(this.this$0)[this.currentImg], this.field_1, this.field_2, 36);
  109.       Location[] locations = this.ballsEngine.getLocations();
  110.       g.setGrayScale(0);
  111.  
  112.       for(int i = 0; i < locations.length; ++i) {
  113.          g.fillArc(locations[i].x, locations[i].y, 10, 10, 0, 360);
  114.          if ((locations[i].x < this.field_1 && locations[i].x > this.field_1 - 10 || locations[i].x > this.field_1 && locations[i].x < this.field_1 + 20) && locations[i].y < this.field_2 && locations[i].y > this.field_2 - 25) {
  115.             this.end = true;
  116.             this.goOn = false;
  117.             this.stopAnimation();
  118.          }
  119.       }
  120.  
  121.       ++this.currentImg;
  122.       if (this.currentImg > 5) {
  123.          this.currentImg = 0;
  124.       }
  125.  
  126.    }
  127. }
  128.